//
//  YQPPMainViewController.m
//  项目基础框架
//
//  Created by NetEase on 16/3/10.
//  Copyright © 2016年 NetEase-yangqian. All rights reserved.
//

#import "YQPPMainViewController.h"
#import "YQPPFirstViewController.h"
#import "YQPPSecondViewController.h"
#import "YQPPThirdViewController.h"
#import "YQPPFourthViewController.h"

@interface YQPPMainViewController ()

{
@private
    YQPPFirstViewController *_firstVC;//第一个vc
    YQPPSecondViewController *_secondVC;//第二个vc
    YQPPThirdViewController *_thirdVC;//第三个vc
    YQPPFourthViewController *_fourthVC;//第四个vc
}

@end

@implementation YQPPMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _firstVC = [[YQPPFirstViewController alloc] init];
    [self addChidVC:_firstVC title:@"首页" image:[UIImage imageNamed:@"first_normal"] selectImage:[UIImage imageNamed:@"first_select"]];
    _secondVC = [[YQPPSecondViewController alloc] init];
    [self addChidVC:_secondVC title:@"二页" image:[UIImage imageNamed:@"second_normal"] selectImage:[UIImage imageNamed:@"second_select"]];
    _thirdVC = [[YQPPThirdViewController alloc] init];
    [self addChidVC:_thirdVC title:@"三页" image:[UIImage imageNamed:@"third_normal"] selectImage:[UIImage imageNamed:@"third_select"]];
    _fourthVC = [[YQPPFourthViewController alloc] init];
    [self addChidVC: _fourthVC title: @"四页" image:[UIImage imageNamed:@"fourth_normal"] selectImage: [UIImage imageNamed:@"fourth_select"]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/**
 *  添加子控制器
 *
 *  @param viewController 控制器
 *  @param title          tabbar的title
 *  @param image          未选中的图片
 *  @param selectImage    选中的图片
 */
- (void)addChidVC:(UIViewController *)viewController title:(NSString *)title image:(UIImage *)image selectImage:(UIImage *)selectImage {
    
    //设置图标和标题
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [viewController.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor orangeColor],NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    //包装一个navigationvc
    UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:viewController];
    [self addChildViewController:nvc];
    
}
@end
